// Name: Analogus_CSS
// Author: ANALOGUS

// Description: 
// Alters CSS-Style on the fly within EBOOKs
// New CSS-editing options in PRS-options
// Zoom-Lock in FontSyzeOverlay
//
// Uses icon-defs not compatible with original defs in PRS+
// Uses localizing not compatible with original PRS+

// To be done: 
// find a way to combine 2 lines in one single line with exec(); 
// 

// History:
// Initial version: 02.04.2012
// 11.04.2012: added option for using external CSS-configuration-file
// 12.04.2012: partly rewritten code; enhancement in of external CSS-config-file; 
// 16.04.2012: function remove empty lines in addstyle.css
// 21.04.2012: added padding-option
// 22.04.2012: added flexible use of css-tags for serif fonts
// 25.04.2012: removed option Option_ExternalCSS; add question wether book is epub or not; shorten path to extern.css; other path for tmp.css; clean code; 
// 27.04.2012: shorten code;
// 09.06.2012: Mark Nord - var-definitions, keep new buttons selected;
// 2012-06-10: Mark Nord - UTF-8 encoding, var-defs, now working in BETA-folder & further alterations
// commented functions left intintionally to show progress;
// Option values should be chosen more practically, so one can save some "shifting"
// 2012.06.11: removed bug in restoring values; 
// 2012-06.13: resetting option values when resetting CSS-style; 


tmp = function() 
{
	var 	
		mime, 
		current, 
		myFineFontSize,
		myLineHeight,
		PATH_SIZEOVERLAY = kbook.model.container.sandbox.SIZE_OVERLAY_GROUP.sandbox.VIEW.sandbox.SIZE_OVERLAY,
		PATH_SIZEOVERLAYSANDBOX = kbook.model.container.sandbox.SIZE_OVERLAY_GROUP.sandbox.VIEW.sandbox.SIZE_OVERLAY.sandbox,
		NAME = "Analogus_CSS",
		L = Core.lang.getLocalizer("ANALOGUS_CSS"),
		log = Core.log.getLogger(NAME),
		exec = Core.shell.exec,
		doFineFontSize,
		Analogus_CSS,

	
	//returns MIME-type for current book; return-statement: statement for functions returning a value
	// work in progress; working for EPUBs so far:
	MimeType = function ()
		{
			var MIME; 
			if (FileSystem.getMIMEType(kbook.model.currentBook.media.path) == 'application/epub+zip')
				{
					MIME = 'EPUB';					
				};
			return MIME
		},
		
	//activates Zoom-Lock. Same function in TouchSettings_X50.js
	FunctionZoomLock = function () {
			if (kbook.model.STATE === 'PAGE') {
				pageSizeOverlayModel.openCurrentOverlay();
				pageSizeOverlayModel.goZoomMode();
				kbook.model.container.sandbox.ZOOM_OVERLAY.doZoomLock();
			} else {
				kbook.model.doBlink();
			}
		},

	//Testing: copy CSS-Tags to Note and vice versa; not functional without editing note-name in this code
	EditTagsFunction = function (copy) {
			switch (copy) 
				{
					case 'CopyTo':
						exec ('cp -f /Data/Notepads/1334415424314.963.note.txt /Data/CSS/extern.css'); 
						break;
					case 'CopyFrom':
						exec ('cp -f /Data/CSS/extern.css /Data/Notepads/1334415424314.963.note.txt'); 
						break;
				}
		},
		
			
	//Deletes additional lines with 'MARKER'-string in style.css to avoid double lines:
	DelAddCSSLines = function () {
			exec('cat /Data/database/system/PRSPlus/epub/style.css | sed /MARKER/d > /Data/CSS/temp.css; mv /Data/CSS/temp.css /Data/database/system/PRSPlus/epub/style.css');
		},

	//Combines style.css + addstyle.css, output: style.css; used in EpubUserStyle.js
	AppendCSS = function () 
		{
			DelAddCSSLines(); 
			exec('cat /Data/database/system/PRSPlus/epub/style.css /Data/CSS/addstyle.css > /Data/CSS/temp.css; cat /Data/CSS/temp.css > /Data/database/system/PRSPlus/epub/style.css');	
		},
	//Deletes empty lines in addstyle.css:
	DeleteEmptyLines = function () 
		{
			exec("sed '/^$/d' /Data/CSS/addstyle.css > /Data/CSS/temp.css; mv /Data/CSS/temp.css /Data/CSS/addstyle.css");
		},

	//Reformats current book:
	ReformatBook = function () 
		{
			if (!model.currentBook) return;
			var data = kbook.bookData;
			model.currentBook.media.browseTo(data, undefined, undefined, undefined, undefined, false, data.width, data.height, data.book.facing);
			data.book.dataChanged();
		},
		
	//Adds line 20 from extern.css to style.css. Used in EpubUserStyle.js:
	FillInSerifTags = function () 
		{
		exec("awk 'FNR==20' /Data/CSS/extern.css >> /Data/database/system/PRSPlus/epub/style.css");
		},
		
		
	//Sets Font-Size in addstyle.css
	FontSizeFunction = function (type) {
		//Cleanup addstyle.css:
		DeleteEmptyLines();
		exec('cat /Data/CSS/addstyle.css | sed /MFONTSIZE/d > /Data/CSS/temp.css; mv /Data/CSS/temp.css /Data/CSS/addstyle.css');	
	
		if (MimeType() == 'EPUB')
		{
			switch (type) 
			{
				case 'Size1':
					exec("awk 'FNR==2' /Data/CSS/extern.css | sed  's/placeholder/1.00em/' >> /Data/CSS/addstyle.css"); 
				break ;
				case 'Size2':
					exec("awk 'FNR==2' /Data/CSS/extern.css | sed  's/placeholder/1.033em/' >> /Data/CSS/addstyle.css"); 
				break ;
				case 'Size3':
					exec("awk 'FNR==2' /Data/CSS/extern.css | sed  's/placeholder/1.066em/' >> /Data/CSS/addstyle.css"); 
				break ;
				case 'Size4':
					exec("awk 'FNR==2' /Data/CSS/extern.css | sed  's/placeholder/1.10em/' >> /Data/CSS/addstyle.css"); 
				break ;
				case 'Size5':
					exec("awk 'FNR==2' /Data/CSS/extern.css | sed  's/placeholder/1.20em/' >> /Data/CSS/addstyle.css"); 
				break ;
				case 'Size6':
					exec("awk 'FNR==2' /Data/CSS/extern.css | sed  's/placeholder/1.30em/' >> /Data/CSS/addstyle.css"); 
				break;
			}	
		}
		
		else 
		{
			MSG(L('NO_EPUB'));
		}
			AppendCSS();		
			BookReload();
	},
	
	//Sets text-indent in addstyle.css
	TextIndentFunction = function (type) {
		//Cleanup addstyle.css:
		DeleteEmptyLines();
		exec('cat /Data/CSS/addstyle.css | sed /MTEXTINDENT/d > /Data/CSS/temp.css; mv /Data/CSS/temp.css /Data/CSS/addstyle.css');	

		switch (type) 
		{
			case 'value1':
				exec("awk 'FNR==14' /Data/CSS/extern.css | sed  's/placeholder/0em/' >> /Data/CSS/addstyle.css"); 
				break ;
			case 'value2':
				exec("awk 'FNR==14' /Data/CSS/extern.css | sed  's/placeholder/1.5em/' >> /Data/CSS/addstyle.css"); 
				break ;
			case 'value3':
				exec("awk 'FNR==14' /Data/CSS/extern.css | sed  's/placeholder/2em/' >> /Data/CSS/addstyle.css");
				break;
		}
		
		AppendCSS();		
		BookReload();
	},


	//Sets line-height in addstyle.css
	LineHeightFunction = function (type) {		
		//Cleanup addstyle.css:
		DeleteEmptyLines();
		exec('cat /Data/CSS/addstyle.css | sed /MLINEHEIGHT/d > /Data/CSS/temp.css; mv /Data/CSS/temp.css /Data/CSS/addstyle.css');
	
		if (MimeType() == 'EPUB')
			{
				switch (type) 
				{
					case 'Size1':
						exec("awk 'FNR==5' /Data/CSS/extern.css | sed  's/placeholder/1em/' >> /Data/CSS/addstyle.css"); 
						break;
					
					case 'Size2':
						exec("awk 'FNR==5' /Data/CSS/extern.css | sed  's/placeholder/1.25em/' >> /Data/CSS/addstyle.css"); 
						break;
					
					case 'Size3':
						exec("awk 'FNR==5' /Data/CSS/extern.css | sed  's/placeholder/1.5em/' >> /Data/CSS/addstyle.css"); 
						break;
					
					case 'Size4':
						exec("awk 'FNR==5' /Data/CSS/extern.css | sed  's/placeholder/2em/' >> /Data/CSS/addstyle.css"); 
						break;
				}
			}
		else 
			{
				MSG(L('NO_EPUB'));
			}		
		
		AppendCSS();		
		BookReload();
	},
	
	
	//Sets text-align in addstyle.css
	TextAlignFunction = function (type) {	
		//Cleanup addstyle.css:
		DeleteEmptyLines();
		exec('cat /Data/CSS/addstyle.css | sed /MALIGN/d > /Data/CSS/temp.css; mv /Data/CSS/temp.css /Data/CSS/addstyle.css');	
		
		switch (type) 
			{
			case 'left':
				exec("awk 'FNR==11' /Data/CSS/extern.css | sed  's/placeholder/left/' >> /Data/CSS/addstyle.css"); 				
				break ;   
			case 'justify':
				exec("awk 'FNR==11' /Data/CSS/extern.css | sed  's/placeholder/justify/' >> /Data/CSS/addstyle.css"); 
				break ; 	
			case 'center':
				exec("awk 'FNR==11' /Data/CSS/extern.css | sed  's/placeholder/center/' >> /Data/CSS/addstyle.css"); 
				break;	
			}
			
		AppendCSS();		
		BookReload();
	},
	
	
	//Sets page-margins in addstyle.css
	PageMarginFunction = function (type) {		
		//Cleanup addstyle.css:
		DeleteEmptyLines();
		exec('cat /Data/CSS/addstyle.css | sed /MMARGIN/d > /Data/CSS/temp.css; mv /Data/CSS/temp.css /Data/CSS/addstyle.css');		
		{
			switch (type) 
			{
				case 'Size1':
					exec("awk 'FNR==8' /Data/CSS/extern.css | sed  's/placeholder/0em/' >> /Data/CSS/addstyle.css"); 
					break ;   
				case 'Size2':
					exec("awk 'FNR==8' /Data/CSS/extern.css | sed  's/placeholder/0.5em/' >> /Data/CSS/addstyle.css"); 
					break ;  						
				case 'Size3':
					exec("awk 'FNR==8' /Data/CSS/extern.css | sed  's/placeholder/1em/' >> /Data/CSS/addstyle.css");  						
					break;
			}
		}
		AppendCSS();		
		BookReload();
	},
	

	//Sets padding in addstyle.css
	PaddingFunction = function (type) {			
		//Cleanup addstyle.css:	
		DeleteEmptyLines();
		exec('cat /Data/CSS/addstyle.css | sed /MPADDING/d > /Data/CSS/temp.css; mv /Data/CSS/temp.css /Data/CSS/addstyle.css');	
		
		{
			switch (type) 
			{
				case 'Size1':
					exec("awk 'FNR==17' /Data/CSS/extern.css | sed  's/placeholder/0px 0px 0px 0px/' >> /Data/CSS/addstyle.css"); 
				break ;   
				case 'Size2':
					exec("awk 'FNR==17' /Data/CSS/extern.css | sed  's/placeholder/5px 5px 5px 5px/' >> /Data/CSS/addstyle.css"); 
				break ;  						
				case 'Size3':
					exec("awk 'FNR==17' /Data/CSS/extern.css | sed  's/placeholder/10px 10px 10px 10px/' >> /Data/CSS/addstyle.css"); 						
					break;
			}
		}
		
		AppendCSS();		
		BookReload();
	},
	
	//Changes fonts for LRF, TXT & RTF
	LrfFontFunction = function (sysfont) 
		{
			//removes lines if exists in prsp.sh: 
			//to do: question wether prsp.sh exists;
			try 
				{
				exec('cat /Data/database/system/PRSPlus/prsp.sh | sed /tt0011m_.ttf/d > /Data/CSS/temp.sh; cat /Data/CSS/temp.sh > /Data/database/system/PRSPlus/prsp.sh'); 
				}
			catch (e)
				{
				MSG('error in line removed');
				}
				
			//fills in line: folder: /opt0; reason: /tmp will be emptied at restart 
				try
					{
					exec('echo "mount --bind /opt0/tt0011m_.ttf /opt/sony/ebook/FONT/tt0011m_.ttf " >> /Data/database/system/PRSPlus/prsp.sh');
					}
				catch(e)
					{
					MSG('error in line filled');
					}
				
			switch (sysfont) 
				{
					case 'Font1':
						exec('cp -f /Data/fonts/SysFont1/tt0011m_.ttf /opt0');
						break ;
					case 'Font2':
						exec('cp -f /Data/fonts/SysFont2/tt0011m_.ttf /opt0');
						break ;
					case 'Font3':
						exec('cp -f /Data/fonts/SysFont3/tt0011m_.ttf /opt0');
						break ;
					case 'Font4':
						exec('cp -f /Data/fonts/SysFont4/tt0011m_.ttf /opt0');
						break ;
					case 'FontSony': 
						exec('cat /Data/database/system/PRSPlus/prsp.sh | sed /tt0011m_.ttf/d > /Data/CSS/temp.sh; cat /Data/CSS/temp.sh > /Data/database/system/PRSPlus/prsp.sh'); //Sony-Fonts
						break; 
				}

			AutoRestart(); //working after redo var-definitions in Analogus_Options.js

		};

	//Resets user-defined CSS-file: deletes addstyle.css & style.css and produces empty new ones; sets option values to 'NoOption':
	ResetCss = function ()
		{
			exec('rm -f /Data/CSS/addstyle.css; touch /Data/CSS/addstyle.css; rm -f /Data/database/system/PRSPlus/epub/style.css; touch /Data/database/system/PRSPlus/epub/style.css');	
			Analogus_CSS.options.Option_Fontsize = 'NoOption';
			Analogus_CSS.options.Option_Lineheight = 'NoOption';
			Analogus_CSS.options.Option_Pagemargin = 'NoOption';
			Analogus_CSS.options.Option_Textalign = 'NoOption';
			Analogus_CSS.options.Option_Textindent = 'NoOption';					
			Analogus_CSS.options.Option_Padding = 'NoOption';
			Core.settings.saveOptions(Analogus_CSS);
			BookReload();
		};

	myInitSizeMenu = function () 
	{
			var btnValue, btnValueTitle;
			//log.trace('Enter myInitSizeMenu; myFineFontSize= '+myFineFontSize);
		/*	PATH_SIZEOVERLAY.model.VAR_RADIO_FONTSIZEFINE = myFineFontSize;
			PATH_SIZEOVERLAY.model.VAR_RADIO_LINEHEIGHT = myLineHeight;

			PATH_SIZEOVERLAY.model.sandbox.VAR_RADIO_FONTSIZEFINE = myFineFontSize;
			PATH_SIZEOVERLAY.model.sandbox.VAR_RADIO_LINEHEIGHT = myLineHeight; */

		try {	
		//	log.trace(Core.debug.dumpToString(PATH_SIZEOVERLAY.model, "SizeOverlay.model. ",1));
		//	log.trace(Core.debug.dumpToString(PATH_SIZEOVERLAY.model.sandbox, "SizeOverlay.model.sandbox. ",1));
		//	log.trace(Core.debug.dumpToString(PATH_SIZEOVERLAYSANDBOX.sizeV, "SizeOverlay.sandbox.sizeV ",1));
		//	log.trace(Core.debug.dumpToString(PATH_SIZEOVERLAYSANDBOX.sizeV.sandbox, "SizeOverlay.sandbox.sizeV.sandbox. ",1));
		//	log.trace(Core.debug.dumpToString(PATH_SIZEOVERLAYSANDBOX.sizeV.sandbox.FONTSIZE, "SizeOverlay.sandbox.sizeV.sandbox.FONTSIZE. ",1));
		//	log.trace(Core.debug.dumpToString(PATH_SIZEOVERLAYSANDBOX.sizeV.sandbox.FONTSIZE.sandbox, "SizeOverlay.sandbox.sizeV.sandbox.FONTSIZE.sandbox. ",1));
		//	log.trace(Core.debug.dumpToString(PATH_SIZEOVERLAYSANDBOX.sizeV.sandbox.FONTSIZE.sandbox.varBtn, "SizeOverlay.sandbox.sizeV.sandbox.FONTSIZE.sandbox.varBtn. ",1));
			
		// done here the very long way to show the principle
		// 	
			switch (Analogus_CSS.options.Option_Fontsize) 
			{
					/* how to handle NoOption ? */
					case 'NoOption':  myFineFontSize = 0;
							break;	
					case 'Size1':  myFineFontSize = 6;
							break;	
					case 'Size2':  myFineFontSize = 7;
							break;	
					case 'Size3':  myFineFontSize = 8;
							break;	
					case 'Size4':  myFineFontSize = 9;
							break;	
			}

			switch (Analogus_CSS.options.Option_Lineheight) {
					/* how to handle NoOption ? */
					case 'NoOption':  myLineHeight = 0;
							break;	
					case 'Size1':  myLineHeight = 1;
							break;	
					case 'Size2':  myLineHeight = 2;
							break;	
					case 'Size3':  myLineHeight = 3;
							break;	
					case 'Size4':  myLineHeight = 4;
							break;	
			}
			
		if (PATH_SIZEOVERLAYSANDBOX.sizeV.sandbox.FONTSIZE.sandbox.varBtn) 
			{
				//log.trace('try Button-Text');
				switch (Core.addonByName.Analogus_Options.options.VarButtonSizeOverlay) 
					{
						case 'value1':  btnValueTitle = L('ShortCaption1'); 
								break;	
						case 'value2':  btnValueTitle = L('ShortCaption2');
								break;	
						case 'value3':  btnValueTitle = L('ShortCaption3');
								break;	
						case 'value4':  btnValueTitle = L('ShortCaption4');
								break;	
						case 'value5':  btnValueTitle = L('ShortCaption5'); 
								break;	
					}
				
				Core.system.setSoValue(PATH_SIZEOVERLAYSANDBOX.sizeV.sandbox.FONTSIZE.sandbox.varBtn, 'text', btnValueTitle);
			} 
			
			log.trace('After Button-Text');
		} catch (e) {
			log.error('Button-addressing failed ',e);
		}	
		/*	doesn't make a change
			Core.system.setSoValue(PATH_SIZEOVERLAYSANDBOX.sizeV.sandbox.FONTSIZEFINE.sandbox.font6, 'variableUpdate', true);
			Core.system.setSoValue(PATH_SIZEOVERLAYSANDBOX.sizeV.sandbox.FONTSIZEFINE.sandbox.font7, 'variableUpdate', true);
			Core.system.setSoValue(PATH_SIZEOVERLAYSANDBOX.sizeV.sandbox.FONTSIZEFINE.sandbox.font8, 'variableUpdate', true);
			Core.system.setSoValue(PATH_SIZEOVERLAYSANDBOX.sizeV.sandbox.FONTSIZEFINE.sandbox.font9, 'variableUpdate', true); */
			
			Core.system.setSoValue(PATH_SIZEOVERLAYSANDBOX.sizeV.sandbox.FONTSIZEFINE.sandbox['font'+myFineFontSize], 'value', 1);
			Core.system.setSoValue(PATH_SIZEOVERLAYSANDBOX.sizeV.sandbox.LINEHEIGHT.sandbox['line'+myLineHeight], 'value', 1);

		//	log.trace('myInitSizeMenu; get VAR_RADIO_FONTSIZEFINE= ' + Core.system.getSoValue(PATH_SIZEOVERLAY.model,'VAR_RADIO_FONTSIZEFINE'));

			log.trace('Exit myInitSizeMenu');
		};
		

//---------taking commands from/functions for Font_Size_Overlay-buttons:--------------------------------
	
	//Fontsize-Changing over Font_Size_Overlay:
	//doFontSizeN: own variable to be found in sizeOverlay.xml:
		doFineFontSize = function (sender) 
		{
			var id;
		//	log.trace('sender.id: '+sender.id);
			id = sender.id.substring(4,5);
		//	log.trace('id: '+id);
		//	log.trace('Size+(id-5): '+ 'Size'+(id-5));
			FontSizeFunction('Size'+(id-5));
			myFineFontSize = id *1;
			Core.system.setSoValue(PATH_SIZEOVERLAYSANDBOX.sizeV.sandbox.FONTSIZEFINE.sandbox['font'+id],"value",1);
			Core.system.setSoValue(PATH_SIZEOVERLAYSANDBOX.sizeV.sandbox.LINEHEIGHT.sandbox['line'+myLineHeight],"value",1);
			//next 2 lines: saving option-values directly:
			Analogus_CSS.options.Option_Fontsize = 'Size'+(id-5);
			Core.settings.saveOptions(Analogus_CSS);
		};


		/* replace doFontSize# in sizeOverlay.xml with doFineFontSize and delete the following functions */
		PATH_SIZEOVERLAYSANDBOX.doFontSize6  = function (sender) {
			doFineFontSize(sender);
		/*	FontSizeFunction('Size1');
			myFineFontSize = 6;	
			Core.system.setSoValue(PATH_SIZEOVERLAYSANDBOX.sizeV.sandbox.FONTSIZEFINE.sandbox.font6,"value",1);
			Core.system.setSoValue(PATH_SIZEOVERLAY.model, 'VAR_RADIO_FONTSIZEFINE', myFineFontSize); */
		};
		PATH_SIZEOVERLAYSANDBOX.doFontSize7  = function (sender) {
			doFineFontSize(sender);
		/*	FontSizeFunction('Size2');
			myFineFontSize = 7;
			Core.system.setSoValue(PATH_SIZEOVERLAYSANDBOX.sizeV.sandbox.FONTSIZEFINE.sandbox.font7,"value",1);
			Core.system.setSoValue(PATH_SIZEOVERLAY.model, 'VAR_RADIO_FONTSIZEFINE', myFineFontSize); */
		};
		PATH_SIZEOVERLAYSANDBOX.doFontSize8  = function (sender) {
			doFineFontSize(sender);
		/*	FontSizeFunction('Size3');
			myFineFontSize = 8;
			Core.system.setSoValue(PATH_SIZEOVERLAYSANDBOX.sizeV.sandbox.FONTSIZEFINE.sandbox.font8,"value",1);
			Core.system.setSoValue(PATH_SIZEOVERLAY.model, 'VAR_RADIO_FONTSIZEFINE', myFineFontSize); */
		};
		PATH_SIZEOVERLAYSANDBOX.doFontSize9  = function (sender) {
			doFineFontSize(sender);
		/*	FontSizeFunction('Size4');
			myFineFontSize = 9;
			Core.system.setSoValue(PATH_SIZEOVERLAYSANDBOX.sizeV.sandbox.FONTSIZEFINE.sandbox.font9,"value",1);
			Core.system.setSoValue(PATH_SIZEOVERLAY.model, 'VAR_RADIO_FONTSIZEFINE', myFineFontSize); */
		};

	//Lineheight-Changing over Font_Size_Overlay
	//doLineHeightN: to be found in sizeOverlay.xml:
		doLineHeight = function (sender) 
		{
			var id;
		//	log.trace('sender.id: '+sender.id);
			id = sender.id.substring(4,5);
		//	log.trace('id: '+id);
		//	log.trace('Size+(id-5): '+ 'Size'+(id-5));
			LineHeightFunction('Size'+id);
			myLineHeight = id * 1;	
			Core.system.setSoValue(PATH_SIZEOVERLAYSANDBOX.sizeV.sandbox.LINEHEIGHT.sandbox['line'+id],"value",1);
			Core.system.setSoValue(PATH_SIZEOVERLAYSANDBOX.sizeV.sandbox.FONTSIZEFINE.sandbox['font'+myFineFontSize],"value",1);
			//next 2 lines: saving options-values directly:
			Analogus_CSS.options.Option_Lineheight = 'Size'+id;	
			Core.settings.saveOptions(Analogus_CSS);
		};

		/* replace doLineHeight# in sizeOverlay.xml with doLineHeight and delete the following functions */
		PATH_SIZEOVERLAYSANDBOX.doLineHeight1  = function (sender) {
			doLineHeight(sender);
		/*	LineHeightFunction('Size1');
			myLineHeight = 1;	
			Core.system.setSoValue(PATH_SIZEOVERLAYSANDBOX.sizeV.sandbox.LINEHEIGHT.sandbox.line1,"value",1);
			Core.system.setSoValue(PATH_SIZEOVERLAY.model, 'VAR_RADIO_LINEHEIGHT', myLineHeight); */
		};
		PATH_SIZEOVERLAYSANDBOX.doLineHeight2  = function (sender) {
			doLineHeight(sender);
		/*	LineHeightFunction('Size2');
			myLineHeight = 2;	
			Core.system.setSoValue(PATH_SIZEOVERLAYSANDBOX.sizeV.sandbox.LINEHEIGHT.sandbox.line2,"value",1);
			Core.system.setSoValue(PATH_SIZEOVERLAY.model, 'VAR_RADIO_LINEHEIGHT', myLineHeight); */
		};
		PATH_SIZEOVERLAYSANDBOX.doLineHeight3  = function (sender) {
			doLineHeight(sender);
		/*	LineHeightFunction('Size3');
			myLineHeight = 3;	
			Core.system.setSoValue(PATH_SIZEOVERLAYSANDBOX.sizeV.sandbox.LINEHEIGHT.sandbox.line3,"value",1);
			Core.system.setSoValue(PATH_SIZEOVERLAY.model, 'VAR_RADIO_LINEHEIGHT', myLineHeight); */
		};
		PATH_SIZEOVERLAYSANDBOX.doLineHeight4  = function (sender) {
			doLineHeight(sender);
		/*	LineHeightFunction('Size4');
			myLineHeight = 4;	
			Core.system.setSoValue(PATH_SIZEOVERLAYSANDBOX.sizeV.sandbox.LINEHEIGHT.sandbox.line4,"value",1);
			Core.system.setSoValue(PATH_SIZEOVERLAY.model, 'VAR_RADIO_LINEHEIGHT', myLineHeight); */
		};

	//Activates Zoom-Lock (former: normal zoom-mode) over Font_Size_Overlay		
		PATH_SIZEOVERLAYSANDBOX.goZoomLock = function () {
			FunctionZoomLock();	
		};
		
	//Test: does not work:
	/*
		PATH_SIZEOVERLAYSANDBOX.IsEpub = function ()
		{
			if (MimeType() == 'EPUB')
				{value = 'true';}
			else
				{value = 'false'};
			return  value;	
		};
	*/

//-----------------------------------------------------------------------------------------------------
	Analogus_CSS = 
	{
		name: NAME,
		settingsGroup: "fonts", 
		title: L("GROUP_BOOK_FORMAT"),	
		icon: "BOOKOPEN", 		
		onInit: function () 
			{
				//Core.hook.hookAfter(..context to be found.. pageSizeOverlayModel, "initSizeMenu", myInitSizeMenu  )
				//Mark Nord 9.6.2012 - functional myInitSizeMenu is executed:
				Core.hook.hookAfter(pageSizeOverlayModel, "initSizeMenu", myInitSizeMenu); 
				log.trace('hooking done');
			},

		optionDefs:
		[
			//Group 1
			{ 
			groupTitle: L('CSS_OPTIONS'),
			groupIcon: 'FONT',
			helpText: L('HELP_CSS_EDITING'),
			optionDefs: 
				[
					{
						name: 'Option_Fontsize',	
						title: L('OPTION_FONTSIZE'),
						icon: 'FONT',
						//helpText: L('HELP_FONTSIZE'),
						defaultValue: 'NoOption',
						values: ['NoOption', 'Size1', 'Size2', 'Size3', 'Size4', 'Size5', 'Size6'],
						valueTitles: 
							{
							'NoOption': L('OPTION_NO_OPTION'), 
							'Size1': L('OPTION_FONTSIZE_1'),	
							'Size2': L('OPTION_FONTSIZE_2'),
							'Size3': L('OPTION_FONTSIZE_3'),
							'Size4': L('OPTION_FONTSIZE_4'),
							'Size5': L('OPTION_FONTSIZE_5'),
							'Size6': L('OPTION_FONTSIZE_6')
							}
					},
					
					{
						name: 'Option_Lineheight',	
						title: L('OPTION_LINEHEIGHT'),
						icon: 'FONT',
						//helpText: L('HELP_LINEHEIGHT'),
						defaultValue: 'NoOption',
						values: ['NoOption', 'Size1', 'Size2', 'Size3', 'Size4'],
						valueTitles: 
							{
							'NoOption': L('OPTION_NO_OPTION'), 
							'Size1': L('OPTION_LINEHEIGHT_1'),	
							'Size2': L('OPTION_LINEHEIGHT_2'),
							'Size3': L('OPTION_LINEHEIGHT_3'),
							'Size4': L('OPTION_LINEHEIGHT_4')
							}
					},
					
					{
						name: 'Option_Pagemargin',	
						title: L('OPTION_PAGEMARGIN'),
						icon: 'FONT',
						//helpText: L('HELP_PAGEMARGIN'),
						defaultValue: 'NoOption',
						values: ['NoOption', 'Size1', 'Size2', 'Size3'],
						valueTitles: 
							{
							'NoOption': L('OPTION_NO_OPTION'), 
							'Size1': L('OPTION_PAGEMARGIN1'), //no margins					
							'Size2': L('OPTION_PAGEMARGIN2'), 
							'Size3': L('OPTION_PAGEMARGIN3')
							}
					},
					
					{
						name: 'Option_Padding',	
						title: L('OPTION_PADDING'),
						icon: 'FONT',
						//helpText: L('HELP_PADDING'),
						defaultValue: 'NoOption',
						values: ['NoOption', 'Size1', 'Size2', 'Size3'],
						valueTitles: 
							{
							'NoOption': L('OPTION_NO_OPTION'), 
							'Size1': L('PADDING1'), 					
							'Size2': L('PADDING2'), 
							'Size3': L('PADDING3')
							}
					},					
										
					{
						name: 'Option_Textalign',	
						title: L('OPTION_TEXTALIGN'),
						icon: 'FONT',
						//helpText: L('HELP_PAGEMARGIN'),
						defaultValue: 'NoOption',
						values: ['NoOption', 'left', 'justify', 'center'],
						valueTitles: 
							{
							'NoOption': L('OPTION_NO_OPTION'), 
							'left': L('OPTION_TEXTALIGN1'), 
							'justify': L('OPTION_TEXTALIGN2'),
							'center': L('OPTION_TEXTALIGN3')
							}
					},
					
					{
						name: 'Option_Textindent',	
						title: L('OPTION_TEXTINDENT'),
						icon: 'FONT',
						//helpText: L('HELP_PAGEMARGIN'),
						defaultValue: 'NoOption',
						values: ['NoOption', 'value1', 'value2', 'value3'],
						valueTitles: 
							{
							'NoOption': L('OPTION_NO_OPTION'), 
							'value1': L('OPTION_TEXTINDENT1'),
							'value2': L('OPTION_TEXTINDENT2'), 
							'value3': L('OPTION_TEXTINDENT3')
							}
					},

					{
						name: 'Reset_CSS',	
						title: L('RESET_CSS'),
						icon: 'BACK',
						helpText: L('HELP_RESET_CSS'),
						defaultValue: 'NO_OPTION',
						values: ['RESET'],
						valueTitles: 
							{
							//'NO_OPTION': L('NO_OPTION'), 
							'RESET': L('RESET')
							}
					},
				]
			},	
			//Group 2
			{
				//fonts for LRF, TXT & RTF:
			groupTitle: L('LRF_OPTIONS'),
			groupIcon: 'FONT',
			optionDefs: 			
				[
					{
						name: 'LrfFont',	
						title: L('OPTION_SYSTEM_FONTS'),
						icon: 'FONT',
						helpText: L('HELP_SYSTEM_FONTS'),
						defaultValue: 'FontSony',
						values: ['Font1', 'Font2', 'Font3', 'Font4', 'FontSony'],
						valueTitles: 
							{
							'Font1': L('ACTION_SYSTEM_FONT_1'),
							'Font2': L('ACTION_SYSTEM_FONT_2'),
							'Font3': L('ACTION_SYSTEM_FONT_3'), 
							'Font4': L('ACTION_SYSTEM_FONT_4'), 
							'FontSony': L('ACTION_SYSTEM_FONT_SONY')
							}
					},
				]
			}, 
			
			//no group:
			{
			name: 'Option_Edit_Tags',	
			title: L('EDIT_CSS_TAGS'),
			icon: 'FONT',
			helpText: L('HELP_EDIT_TAGS'),
			defaultValue: 'NoOption',
			values: ['NoOption', 'CopyTo', 'CopyFrom'],
			valueTitles: 
				{
				'NoOption': L('OPTION_NO_OPTION'), 
				'CopyTo': L('OPTION_COPY_TO'), 					
				'CopyFrom': L('OPTION_COPY_FROM')
				}
					
			},			
		],

//----------------------------------------------------------------------------------------------------------
		//Called from Core_Settings.js after changing options:
		
		onSettingsChanged: function (propertyName, oldValue, newValue, object) 
		{
			switch (propertyName) 
			{
				case 'Option_Fontsize':
						FontSizeFunction (newValue);	
					break ;	
				case 'Option_Lineheight':
						LineHeightFunction (newValue) ;
					break ;	
				case 'Option_Pagemargin':
						PageMarginFunction (newValue) ;
					break ;	
				case 'Option_Padding':
						PaddingFunction (newValue) ;
					break ;		
				case 'Option_Textalign':
						TextAlignFunction (newValue) ;
					break ;	
				case 'Option_Textindent':
						TextIndentFunction (newValue) ;
					break; 
				case 'LrfFont':
						LrfFontFunction (newValue) ;	
					break ;					
				case 'Reset_CSS':
						ResetCss ();
					break ;					
				case 'Option_Edit_Tags':
						EditTagsFunction(newValue); 
					break ;										
			}
		}
	};

	Core.addAddon(Analogus_CSS);
};


try 
{
	tmp();
} catch (e) 
{
	// Core's log
	log.error("in Analogus_CSS.js", e);
}
